import { resultSuccess, type requestParams } from '../utils'

interface UserList {
  id?: number
  avatar?: string
  name: string
  // name: string,
  phone: string
  email: string
  password?: string
  sex: 0 | 1 // 0-男 1-女
  status: 0 | 1 // 1-正常 0-禁用
  roles?: number[]
  token?: string
  [key: string]: any
}
export let userInfo: UserList[] = [
  {
    id: 1,
    avatar: '/logo.webp',
    name: 'admin',
    // name: '管理员',
    phone: '18308797777',
    password: '5232319b0da1028c09399b78e0361b61',
    email: 'ddd@126.com',
    sex: 0, // 0-男 1-女
    status: 1, // 1-正常 0-禁用
    roles: [1],
    token: 'Admin Token',
  },
  {
    id: 2,
    avatar: '/logo.webp',
    name: 'sysAdmin',
    // name: '系统管理员',
    phone: '18308797777',
    password: 'widgets@123',
    email: 'ddd@126.com',
    sex: 1, // 0-男 1-女
    status: 0, // 1-正常 0-禁用
    roles: [1],
    token: 'system Token',
  },
]

export const captcha = '<svg xmlns="http://www.w3.org/2000/svg" width="100" height="28" viewBox="0,0,100,34"><path d="M16 6 C68 10,30 5,89 14" stroke="#333" fill="none"/><path d="M16 31 C41 22,52 24,94 6" stroke="#999" fill="none"/><path d="M20 3 C63 2,36 26,81 26" stroke="#444" fill="none"/><path d="M2 7 C48 2,33 28,96 5" stroke="#333" fill="none"/><path d="M21 5 C63 6,34 16,87 7" stroke="#777" fill="none"/><path fill="#222" d="M15.80 20.54L15.81 20.56L15.83 20.58Q13.11 20.68 12.35 22.92L12.30 22.87L12.30 22.88Q12.12 23.65 12.01 24.30L11.92 24.21L11.91 24.20Q14.49 24.37 16.12 24.37L16.17 24.42L16.10 24.35Q17.76 24.37 20.35 24.26L20.35 24.26L20.44 24.35Q20.29 22.60 18.88 21.54L19.00 21.65L19.00 21.65Q17.69 20.65 15.90 20.65ZM15.98 33.22L15.98 33.21L15.86 33.09Q11.79 33.25 10.50 31.85L10.51 31.86L10.51 31.86Q9.48 30.33 9.32 27.05L9.37 27.10L9.32 27.05Q9.25 26.75 9.17 25.38L9.23 25.44L9.23 25.43Q9.18 23.22 9.18 22.49L9.19 22.51L9.06 22.37Q9.09 20.54 9.82 19.44L9.80 19.42L9.78 19.40Q11.30 18.10 14.27 18.10L14.21 18.04L15.68 17.95L15.66 17.93Q17.87 18.08 19.39 18.39L19.35 18.35L19.34 18.34Q21.42 18.82 22.41 20.04L22.37 20.00L22.32 19.95Q22.94 21.03 23.02 23.12L23.02 23.13L23.20 23.30Q23.02 24.26 23.05 26.43L23.17 26.54L23.05 26.43Q20.31 26.58 17.53 26.58L17.48 26.53L11.94 26.58L11.94 26.59Q12.05 30.96 16.12 30.73L16.11 30.72L16.17 30.78Q19.84 30.49 21.06 28.66L21.15 28.75L21.06 28.66Q22.04 29.30 23.63 30.48L23.63 30.47L23.64 30.48Q22.27 32.88 18.12 33.14L17.94 32.97L17.99 33.02Q17.40 33.19 16.03 33.26ZM18.30 35.57L18.20 35.48L18.34 35.62Q19.42 35.55 20.63 35.62L20.54 35.53L20.63 35.62Q25.53 35.72 26.45 32.94L26.54 33.04L26.49 32.99Q24.80 31.67 23.69 30.91L23.72 30.94L23.68 30.90Q23.89 30.54 24.08 30.31L24.08 30.31L24.03 30.26Q23.37 29.87 22.00 28.92L22.09 29.01L21.98 28.89Q22.97 28.85 25.02 29.16L25.13 29.27L25.11 29.25Q24.92 27.88 24.84 27.19L24.81 27.16L24.78 25.34L24.78 25.34Q24.65 23.00 24.00 21.51L23.91 21.42L23.85 21.36Q23.68 21.11 23.10 20.50L23.06 20.46L23.07 20.47Q22.90 20.15 22.68 19.58L22.64 19.55L22.76 19.67Q20.84 17.59 15.77 17.59L15.83 17.65L14.10 17.59L14.15 17.65Q10.81 17.54 9.37 19.02L9.49 19.15L9.45 19.11Q8.63 20.07 8.66 22.13L8.85 22.31L8.70 22.17Q8.88 23.26 8.99 25.50L9.02 25.53L9.01 25.52Q9.11 27.15 9.23 29.20L9.14 29.12L9.07 29.04Q9.33 31.28 10.20 32.35L10.21 32.35L10.36 32.50Q10.33 32.47 10.52 32.59L10.59 32.66L10.92 33.33L10.89 33.30Q11.58 35.06 18.17 35.44ZM16.18 30.37L16.15 30.34L16.20 30.38Q14.91 30.35 14.00 29.90L14.04 29.94L14.12 30.02Q14.00 29.56 13.81 28.88L13.89 28.95L13.84 28.91Q15.55 28.83 17.15 28.83L17.17 28.85L17.12 28.79Q18.85 28.86 20.53 28.97L20.48 28.92L20.47 28.91Q19.11 30.18 16.10 30.29ZM17.70 22.90L17.75 22.96L17.76 22.96Q18.42 23.02 19.76 23.40L19.75 23.39L19.96 23.79L19.85 23.87L20.03 24.06Q18.50 24.01 17.58 23.97L17.73 24.12L17.71 24.10Q15.34 23.97 15.30 23.97L15.31 23.97L15.36 24.02Q16.02 23.01 17.69 22.89Z"/><path fill="#444" d="M39.41 31.81L39.54 31.94L37.44 31.79L37.54 31.88Q36.61 31.91 35.66 32.02L35.63 31.99L35.69 32.05Q36.17 25.75 36.17 21.75L36.13 21.71L36.18 21.77Q32.19 15.07 24.54 6.39L24.60 6.46L24.58 6.43Q26.25 7.31 29.60 8.11L29.72 8.23L29.70 8.20Q34.83 13.87 37.84 19.08L37.78 19.03L37.86 19.10Q40.79 13.47 45.16 8.44L45.12 8.40L45.08 8.35Q47.55 8.01 50.06 7.21L50.13 7.28L50.11 7.26Q43.97 13.26 39.10 21.68L39.08 21.66L39.16 21.74Q39.19 28.81 39.49 31.89ZM48.63 9.36L51.26 6.42L51.28 6.45Q48.09 7.52 44.97 7.98L45.04 8.05L45.13 8.14Q40.78 12.74 37.96 17.84L38.01 17.89L38.10 17.98Q35.81 14.17 32.62 10.28L32.70 10.36L32.75 10.42Q32.42 10.36 31.93 10.28L31.81 10.17L32.00 10.35Q31.18 9.42 29.66 7.75L29.73 7.81L29.80 7.89Q26.23 6.94 23.26 5.38L23.35 5.47L23.39 5.51Q30.98 13.86 35.74 21.78L35.78 21.83L35.78 21.82Q35.80 28.28 35.19 32.43L35.10 32.34L35.20 32.44Q35.83 32.31 37.28 32.19L37.41 32.32L37.33 33.27L37.41 33.35Q37.37 33.76 37.29 34.30L37.28 34.28L37.34 34.34Q40.75 34.22 42.50 34.41L42.53 34.43L42.57 34.47Q41.29 29.77 41.17 23.79L41.21 23.83L41.19 23.81Q45.60 15.39 52.15 8.04L52.02 7.91L48.56 9.29Z"/><path d="M1 7 C52 21,62 29,80 7" stroke="#111" fill="none"/><path fill="#111" d="M53.22 21.55L53.26 21.59L53.37 21.70Q53.36 25.95 52.64 30.10L52.55 30.02L52.51 29.97Q54.92 29.56 58.00 29.45L57.99 29.44L57.98 29.43Q59.18 29.48 60.24 28.47L60.41 28.65L60.40 28.63Q61.33 27.48 61.33 26.15L61.41 26.24L61.46 26.28Q61.41 25.93 61.37 25.66L61.41 25.71L61.27 25.56Q61.28 22.79 59.03 21.95L58.87 21.79L59.05 21.97Q58.17 21.55 57.49 21.63L57.58 21.72L57.46 21.60Q56.46 21.58 55.43 21.62L55.42 21.62L55.42 21.62Q54.38 21.68 53.36 21.68ZM52.19 11.30L52.03 11.14L52.12 11.24Q53.00 14.55 53.27 18.93L53.17 18.83L53.22 18.88Q54.71 19.04 57.38 19.08L57.27 18.97L57.35 19.06Q60.33 19.14 60.67 15.60L60.60 15.52L60.62 15.55Q60.85 13.64 59.44 12.81L59.32 12.68L59.47 12.83Q58.56 12.30 54.14 11.66L54.10 11.61L54.11 11.62Q53.03 11.45 52.11 11.23ZM48.47 34.12L48.44 34.09L48.41 34.06Q50.98 27.49 50.71 20.10L50.57 19.96L50.65 20.04Q50.25 12.64 47.32 6.17L47.40 6.25L47.45 6.30Q51.21 8.81 57.44 9.05L57.51 9.12L57.48 9.10Q63.62 9.26 63.96 12.15L64.08 12.27L63.95 12.14Q64.30 14.92 62.89 17.59L62.95 17.65L62.88 17.58Q62.20 19.15 60.60 19.83L60.59 19.81L60.54 19.77Q64.17 20.43 64.40 25.79L64.41 25.81L64.53 25.93Q64.55 26.98 64.48 28.39L64.41 28.32L64.39 28.30Q64.47 29.75 63.54 30.68L63.55 30.70L63.49 30.64Q62.54 31.55 61.20 31.70L61.27 31.77L61.21 31.71Q59.82 31.88 58.75 31.88L58.74 31.86L58.78 31.90Q52.98 31.82 48.45 34.10ZM61.15 34.31L61.32 34.48L61.15 34.31Q62.26 34.55 64.13 34.66L64.08 34.61L63.99 34.53Q65.46 34.63 66.57 33.75L66.52 33.71L66.57 33.76Q67.33 32.81 67.22 31.24L67.17 31.19L67.20 31.22Q67.14 30.29 66.42 26.83L66.40 26.81L66.42 26.82Q65.83 23.69 63.96 22.20L63.96 22.20L63.39 21.21L63.45 21.27Q65.24 19.97 65.81 16.21L65.76 16.15L65.80 16.20Q65.81 14.91 65.73 13.50L65.85 13.61L65.87 13.64Q65.80 12.31 64.70 11.48L64.73 11.51L64.70 11.48Q64.28 11.17 64.17 11.14L64.21 11.18L64.14 11.11Q63.89 10.59 63.05 9.79L63.22 9.96L63.13 9.87Q61.62 8.82 57.40 8.63L57.33 8.57L57.49 8.72Q50.84 8.43 46.84 5.54L46.80 5.49L46.80 5.49Q50.14 12.56 50.44 20.10L50.44 20.10L50.30 19.96Q50.74 27.90 47.93 34.83L47.78 34.69L49.94 33.84L49.99 33.89Q49.53 34.94 49.03 36.09L49.04 36.10L49.12 36.17Q53.31 34.20 58.33 34.20L58.43 34.30L58.38 34.25Q59.82 34.27 61.26 34.43ZM59.10 23.85L59.13 23.88L59.20 23.95Q59.83 23.77 60.74 24.23L60.82 24.31L60.75 24.25Q60.95 24.67 61.10 25.73L61.03 25.66L60.97 25.60Q61.12 26.93 60.19 27.98L60.17 27.96L60.22 28.01Q59.37 29.14 57.96 29.02L57.98 29.04L56.46 29.12L56.49 29.16Q55.72 29.19 55.00 29.30L55.03 29.33L54.92 29.22Q55.25 27.42 55.33 23.96L55.30 23.94L55.41 24.04Q55.91 23.82 57.17 23.78L57.25 23.87L57.17 23.78Q58.45 23.77 59.06 23.81ZM58.12 14.31L58.14 14.33L58.53 14.33L58.46 14.26Q58.75 14.33 58.94 14.37L58.90 14.32L59.18 14.22L59.51 14.36L60.14 14.46L60.18 14.50Q60.37 14.84 60.37 15.14L60.38 15.15L60.26 15.57L60.23 15.53Q60.34 16.91 59.47 17.84L59.48 17.85L59.44 17.81Q58.47 18.65 57.26 18.65L57.27 18.67L57.28 18.68Q56.28 18.71 56.28 18.71L56.32 18.75L56.37 18.80Q54.90 18.62 55.24 18.62L55.20 18.58L55.28 18.65Q55.18 17.08 54.88 14.03L54.94 14.09L55.00 14.15Q56.51 14.21 58.03 14.21Z"/><path d="M5 5 C58 8,37 2,87 23" stroke="#999" fill="none"/><path fill="#222" d="M68.75 7.77L68.91 7.93L68.86 7.88Q70.69 12.67 71.26 17.85L71.39 17.99L71.23 17.82Q74.98 13.73 80.88 8.89L80.97 8.99L80.91 8.93Q84.15 8.67 86.78 7.87L86.76 7.85L80.10 13.37L80.09 13.36Q76.71 16.34 73.86 19.20L73.85 19.18L73.82 19.16Q81.82 28.34 86.88 33.06L86.83 33.01L86.88 33.06Q83.74 32.09 81.42 31.94L81.45 31.96L81.55 32.06Q75.65 26.55 71.35 20.72L71.38 20.75L71.40 20.78Q71.53 27.41 69.67 32.74L69.64 32.71L69.65 32.73Q69.51 32.85 69.01 33.05L68.94 32.97L68.89 33.11L68.93 33.15Q68.63 33.08 66.08 34.00L66.23 34.15L66.20 34.11Q69.16 27.56 68.82 20.09L68.85 20.12L68.78 20.05Q68.52 12.79 64.98 6.28L64.90 6.21L65.42 6.46L65.97 6.89L65.86 6.74L65.83 6.71Q66.60 7.14 68.81 7.83ZM69.14 7.59L69.17 7.62L69.18 7.63Q66.78 6.94 64.15 5.42L64.24 5.50L64.19 5.45Q68.52 12.79 68.52 21.74L68.55 21.77L68.44 21.66Q68.50 28.73 65.53 34.78L65.54 34.78L67.60 33.95L67.52 33.87Q67.12 34.88 66.43 36.17L66.42 36.16L66.48 36.22Q68.66 35.35 70.60 34.93L70.67 35.01L70.74 34.84L70.73 34.83Q70.95 34.75 71.52 34.60L71.61 34.69L71.58 34.66Q73.31 28.81 73.42 24.02L73.33 23.92L73.32 23.91Q75.42 26.43 77.25 28.30L77.32 28.37L77.35 28.40Q78.39 29.36 81.39 32.33L81.54 32.47L81.54 32.47L81.45 32.38Q82.48 33.22 84.34 34.82L84.29 34.77L84.34 34.82Q88.30 35.62 91.76 37.33L91.76 37.32L91.74 37.30Q82.34 28.63 76.10 21.21L76.21 21.32L76.10 21.21Q80.49 16.92 89.25 8.32L89.34 8.41L89.27 8.34Q86.83 9.59 84.81 9.97L84.67 9.84L84.70 9.86Q86.04 8.99 88.36 6.98L88.30 6.92L88.23 6.84Q84.18 8.31 80.83 8.51L80.82 8.49L80.88 8.55Q77.96 10.78 73.09 15.46L73.10 15.47L73.04 15.41Q72.58 12.74 72.01 10.19L72.05 10.23L71.99 10.17Q70.93 10.14 69.94 9.79L69.92 9.78L69.89 9.75Q69.68 9.00 69.10 7.55Z"/><path d="M9 13 C50 17,43 5,80 4" stroke="#555" fill="none"/><path d="M13 17 C48 13,33 26,87 27" stroke="#888" fill="none"/><path d="M3 9 C32 13,61 8,93 29" stroke="#555" fill="none"/></svg>'


export default [
  {
    url: '/api/user',
    method: 'get',
    response: (request: requestParams) => {
      const { page, pageSize, name, phone, status } = request.query
      let resultData = userInfo
      if (name) {
        resultData = resultData.filter(item => (item.name.includes(name) || item.name.includes(name)))
      }
      if (phone) {
        resultData = resultData.filter(item => item.phone.includes(phone))
      }
      if (status) {
        resultData = resultData.filter(item => item.status === Number(status))
      }
      const total = resultData.length
      resultData = resultData.slice(page - 1, pageSize)
      return resultSuccess(resultData, '获取数据成功', total)
    }
  },
  {
    url: '/api/user',
    method: 'put',
    response: (request: requestParams) => {
      const index: number = userInfo.findIndex(menu => menu.id === Number(request.body.id))
      const menu: UserList = userInfo[index]
      Object.keys(menu).map(key => {
        menu[key] = request.body[key]
      })
      userInfo[index] = menu
      return resultSuccess('', '修改数据成功')
    }
  },
  {
    url: '/api/user',
    method: 'delete',
    response: (request: requestParams) => {
      request.body.map((item: number | string) => {
        const roles = userInfo.filter(role => role.id != Number(item))
        userInfo = roles
      })
      return resultSuccess('', '删除数据成功')
    }
  },
  {
    url: '/api/user',
    method: 'post',
    response: (request: requestParams) => {
      const id = userInfo[userInfo.length - 1].id || 0
      userInfo.push({ ...request.body, id: id + 1 })
      return resultSuccess('', '新增数据成功')
    }
  }
]